package com.langshixiaobai.admin.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.langshixiaobai.admin.common.convention.result.Result;
import com.langshixiaobai.admin.common.convention.result.Results;
import com.langshixiaobai.admin.dao.entity.UserDO;
import com.langshixiaobai.admin.dto.req.UserLoginReqDTO;
import com.langshixiaobai.admin.dto.req.UserRegisterReqDTO;
import com.langshixiaobai.admin.dto.req.UserUpdateReqDTO;
import com.langshixiaobai.admin.dto.resp.PassengerRespDTO;
import com.langshixiaobai.admin.dto.resp.UserLoginRespDTO;
import com.langshixiaobai.admin.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;


    @RequestMapping("/getPassenger")
    public PassengerRespDTO getPassenger(){
        PassengerRespDTO passengerRespDTO = new PassengerRespDTO().setPhone("111111111111")
                .setIdCard("230521200307270888");

        return passengerRespDTO;
    }

    /**
     * 查询用户名是否存在
     */
    @GetMapping("/getUserInfo")
    public Result< UserDO> getUserInfo(@RequestParam("username") String username){

       UserDO userDO =  userService.getUserInfo(username);
       return Results.success(userDO);
    }


    @RequestMapping("/register")
    public Result<Void> register(@RequestBody  UserRegisterReqDTO requestParam){
        userService.register(requestParam);
//        UserDO userDO = BeanUtil.copyProperties(requestParam, UserDO.class);
//        userMapper.insert(userDO);
        return Results.success();
    }

    /**
     * 修改用户
     */
    @PutMapping("/api/short-link/admin/v1/user")
    public Result<Void> update(@RequestBody UserUpdateReqDTO requestParam) {
        userService.updateUser(requestParam);
        return Results.success();
    }

    /**
     * 用户登录
     */
    @RequestMapping("/userLogin")
    public Result<UserLoginRespDTO> userLogin(@RequestBody UserLoginReqDTO requestParam){
        UserLoginRespDTO userLoginRespDTO =  userService.userLogin(requestParam);
        return Results.success(userLoginRespDTO);
    }

    /**
     * 检查用户是否登录
     */
    @GetMapping("/api/short-link/admin/v1/user/check-login")
    public Result<Boolean> checkLogin(@RequestParam("username") String username, @RequestParam("token") String token) {
        return Results.success(userService.checkLogin(username, token));
    }



}
